<script lang="ts" setup>
import { get, post, message, loadFile, formatOptions } from '@/utils'
import Editor from '@/components/Editor/index.vue'
import { AmountType, RechargeType } from '@/enum/config'
import { FormInstance } from '@arco-design/web-vue'
const props = defineProps<{
  show: boolean
  id: number | string
}>()
const emit = defineEmits(['update:show', 'reset', 'confirm'])
const formRef = ref() as Ref<FormInstance>
const detail = reactive({
  amount: 0,
  amountType: 2,
  type: 1,
  userId: props.id,
})
const submit = done => {
  formRef.value.validate(err => {
    if (!err) {
      const query = Object.assign({}, detail)
      post(
        { url: '/server-user/admin/user/wallet/save', data: query },
        ({ code, msg }) => {
          message({
            type: code == 200 ? 'success' : 'error',
            content: msg,
          })
          emit('update:show', false)
          emit('confirm')
          done(true)
        },
        () => done(false)
      )
    } else done(false)
  })
}
</script>
<template>
  <CDrawer v-model:visible="props.show" @before-ok="submit" :mask-closable="false" title="修改余额" @cancel="emit('update:show', false)" width="500px">
    <div class="content">
      <a-form :model="detail" ref="formRef" :label-col-props="{ span: 6 }" :wrapper-col-props="{ span: 16 }">
        <a-form-item label="变动类型" field="type" :rules="[{ required: true, message: '请选择变动类型' }]" :validate-trigger="['change', 'blur']">
          <a-radio-group v-model="detail.type" :options="formatOptions(RechargeType)" />
        </a-form-item>
        <!-- <a-form-item label="金额类型" field="amountType" :rules="[{ required: true, message: '请选择金额类型' }]" :validate-trigger="['change', 'blur']">
          <a-select placeholder="请选择" v-model="detail.amountType" :options="formatOptions(AmountType)" />
        </a-form-item> -->
        <a-form-item label="变动积分" field="amount" :rules="[{ required: true, message: '请输入变动积分' }]" :validate-trigger="['change', 'blur']">
          <a-input-number :min="0" v-model="detail.amount" placeholder="请输入变动积分" />
        </a-form-item>
      </a-form>
    </div>
  </CDrawer>
</template>
<style lang="less" scoped></style>
